import {
  Component,
  ViewChild,
  Injector,
  Output,
  EventEmitter,
  ElementRef,
  ViewEncapsulation,
} from "@angular/core";
import { ModalDirective } from "ngx-bootstrap";
import { AppComponentBase } from "@shared/common/app-component-base";

import * as moment from "moment";
import { finalize } from "rxjs/operators";
import {
  MainTaskServiceProxy,
  TaskDto,
  MainTaskGoProductionDto,
  NameValueDtoOfNameValueDto,
  PipelineServiceProxy,
  SideTaskServiceProxy,
  PipelineListDto,
  PipelineNodeServiceProxy,
} from "@shared/service-proxies/service-proxies";
import { appModuleAnimation } from "@shared/animations/routerTransition";

@Component({
  selector: "rw26",
  templateUrl: "./rw26.component.html",
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()],
})
export class RW26ModalComponent extends AppComponentBase {
  saving = false;

  pipe: PipelineListDto = new PipelineListDto();
  dueDate = new Date();

  constructor(
    injector: Injector,
    private _pipelineNodesServiceProxy: PipelineNodeServiceProxy
  ) {
    super(injector);
  }

  load(pipe: PipelineListDto): void {
    this.pipe = pipe;
    this.dueDate = this.pipe.dueDatePlanned.toDate();
  }

  save(): void {
    this.saving = true;
    this._pipelineNodesServiceProxy
      .updateDueDate(this.pipe.id, moment(this.dueDate))
      .pipe(
        finalize(() => {
          this.saving = false;
        })
      )
      .subscribe((result) => {
        this.notify.success("保存成功");
      });
  }
}
